<?php
 class Products extends CI_Model{
    
    function __construct(){
        parent::__construct();
    }
    
    /**
     * Get list product index
     * @author tien.nguyen
     * @return array
     */
    public function getListIndex(){
       $this->db->where('Visible', 1);
       $this->db->limit(3);
       $this->db->order_by('CreatedDate', 'DESC');       
       $query = $this->db->get('products');
       return $query->result_array(); 
    }
    
    /**
     * Get list product for product list 
     * @author tien.nguyen
     */
    public function getListProduct($cateId, $page = 1){
        $this->db->from('products');
        $this->db->where('Visible', 1);
       $this->db->limit(10, ($page -1 )*10);
       $this->db->order_by('Ordering', 'ASC');
        $this->db->join('product_categories', 'product_categories.ProductCategoryId =
            products.ProductCategoryId', 'left');
        
        if(!empty($cateId)){
            $this->db->where('product_categories.ProductCategoryId = '.$cateId);
        }
       $query = $this->db->get();
        
       return $query->result_array();
    }
    
    /**
     * Get product
     * @author tien.nguyen
     */
    public function getProduct($productId){
       $query = $this->db->get_where('products', array('ProductId' => $productId));
       return $query->row_array();
    }
 }
?>